home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / appsrcs.zip / APPBAR.ZIP / APPEXEC.C < prev    next >
C/C++ Source or Header  |  1993-06-04  |  8KB  |  228 lines

  1. #define STRICT
  2. #include <windows.h>
  3. #include <windowsx.h>
  4. #include <shellapi.h>
  5. #include <stdarg.h>
  6. #include <stdio.h>
  7. #include <ctype.h>
  8. #include <direct.h>
  9. #include <string.h>
  10. #include "appbar.h"
  11.  
  12. char szError[256];
  13.  
  14. /*--------------------------------------------------------------------------*/
  15. /* FUNCTION: ProgExec(LPSTR lpCmdLine, int nCmdShow)                */
  16. /*                                        */
  17. /* PURPOSE:  changes current drive & directory and executes a program        */
  18. /*--------------------------------------------------------------------------*/
  19. BOOL PASCAL ProgExec(HWND hWndParent, LPSTR lpszFile, LPSTR lpszParams, LPSTR lpszDir, int nCmdShow)
  20.     {
  21.     UINT ExecStatus;
  22.     UINT ShowMode[3] = {SW_SHOWNORMAL, SW_SHOWMAXIMIZED, SW_SHOWMINIMIZED};
  23.     char szParameters[256];
  24.  
  25.     // show maximum sized files as normal, resizing is done later
  26.     if(nCmdShow == 3)
  27.     nCmdShow = 0;
  28.  
  29.     bExecuteProg = TRUE;
  30.  
  31.     lstrcpy((LPSTR) szParameters, lpszParams);
  32.     // if lpszParams contains "?" ask for commandline parameters
  33.     if(strchr(szParameters, '?'))
  34.     AskForParameters(szParameters);
  35.  
  36.     // execute file
  37.     if(bExecuteProg)
  38.     {
  39.     ExecStatus = (UINT) ShellExecute(hWndParent, "open", lpszFile, szParameters, lpszDir, ShowMode[nCmdShow]);
  40.     if(ExecStatus <= 32)
  41.         {
  42.         lstrcpy((LPSTR) szError, (LPCSTR) lpszFile);
  43.         ExecuteErrorHandle(ExecStatus, szError);
  44.         return FALSE;
  45.         }
  46.     else
  47.         return TRUE;
  48.     }
  49.     return TRUE;
  50.     }
  51.  
  52. /*--------------------------------------------------------------------------*/
  53. VOID DoShellTasks(VOID)
  54.     {
  55.     char IniString[4*MAXFILECHARS], *szTemp;
  56.  
  57.     /* launch programs specified by load= */
  58.     GetProfileString("windows", "load", "  ", IniString, (4*MAXFILECHARS)-1);
  59.     if((szTemp = strtok(IniString, " ")) != NULL)
  60.     {
  61.     WinExec(szTemp, SW_SHOWMINIMIZED);
  62.     while((szTemp = strtok(NULL, " ")) != NULL)
  63.         WinExec(szTemp, SW_SHOWMINIMIZED);
  64.     }
  65.  
  66.     /* launch programs specified by run= */
  67.     GetProfileString("windows", "run", "  ", IniString, (4*MAXFILECHARS)-1);
  68.     if((szTemp = strtok(IniString, " ")) != NULL)
  69.     {
  70.     WinExec(szTemp, SW_SHOWNORMAL);
  71.     while((szTemp = strtok(NULL, " ")) != NULL)
  72.         WinExec(szTemp, SW_SHOWNORMAL);
  73.     }
  74.  
  75.     /* launch programs from specified groupfiles */
  76.     GetPrivateProfileString("Shell", "ShellGroup", "startup.grp", szBuffer,
  77.                 255, "appbar.ini");
  78.     if((szTemp = strtok(szBuffer, " ")) != NULL)
  79.     {
  80.     ExecGroupFile(szTemp);
  81.     while((szTemp = strtok(NULL, " ")) != NULL)
  82.         ExecGroupFile(szTemp);
  83.     }
  84.     }
  85.  
  86. /*---------------------------------------------------------------------------/
  87.    Function : StartOrCloseProgram()
  88. /---------------------------------------------------------------------------*/
  89. VOID PASCAL StartOrCloseProgram(int iClose, UINT ClickMode)
  90.     {
  91.     CheckProgStatus();
  92.     if(AppSystem.DoubleClick == 0)
  93.     {
  94.     if(ClickMode == BN_CLICKED)
  95.         {
  96.         if(AppButton[iClose].ProgStatus == ALIVE)
  97.         BringWindowToTop(AppButton[iClose].hWndApp);
  98.  
  99.         if(AppButton[iClose].ProgStatus == NOTALIVE)
  100.         {
  101.         SetCursor(LoadCursor(NULL, IDC_WAIT));
  102.         iActive = iClose+1;
  103.         if((AppSound.EnableSound != 0) && (AppButton[iClose].NoSound == 0))
  104.             {
  105.             if(stricmp(AppSound.ProgramStart, "<none>") != 0)
  106.             sndPlaySound(AppSound.ProgramStart, SND_ASYNC | SND_NODEFAULT);
  107.             }
  108.         ProgExec(hWndMain, (LPSTR)AppButton[iClose].ProgName, (LPSTR)AppButton[iClose].Params, (LPSTR)AppButton[iClose].StartDir, AppButton[iClose].ShowMode);
  109.         if(AppButton[iClose].Close)
  110.             AppButton[iClose].ProgStatus = ALIVE;
  111.         SetCursor(LoadCursor(NULL, IDC_ARROW));
  112.         }
  113.         }
  114.  
  115.     if(ClickMode == BN_DOUBLECLICKED && AppButton[iClose].Close)
  116.         {
  117.         if((AppSound.EnableSound != 0) && (AppButton[iClose].NoSound == 0))
  118.         if(stricmp(AppSound.ProgramClose, "<none>") != 0)
  119.             sndPlaySound(AppSound.ProgramClose, SND_ASYNC | SND_NODEFAULT);
  120.         if(CloseApp(AppButton[iClose].hWndApp, hInst))
  121.         AppButton[iClose].ProgStatus = NOTALIVE;
  122.         InvalidateRect(hWndCurrentButton, (LPRECT) NULL, FALSE);
  123.         UpdateWindow(hWndCurrentButton);
  124.         }
  125.     }
  126.  
  127.     if((AppSystem.DoubleClick == 1) && (ClickMode == BN_DOUBLECLICKED))
  128.     {
  129.     if(AppButton[iClose].ProgStatus == NOTALIVE || !AppButton[iClose].Close)
  130.         {
  131.         SetCursor(LoadCursor(NULL, IDC_WAIT));
  132.         iActive = iClose+1;
  133.         if((AppSound.EnableSound != 0) && (AppButton[iClose].NoSound == 0))
  134.         if(stricmp(AppSound.ProgramStart, "<none>") != 0)
  135.             sndPlaySound(AppSound.ProgramStart, SND_ASYNC | SND_NODEFAULT);
  136.         ProgExec(hWndMain, (LPSTR)AppButton[iClose].ProgName, (LPSTR)AppButton[iClose].Params, (LPSTR)AppButton[iClose].StartDir, AppButton[iClose].ShowMode);
  137.         SetCursor(LoadCursor(NULL, IDC_ARROW));
  138.         }
  139.     else
  140.         {
  141.         //if program still exists, kill it.
  142.         if(IsWindow(AppButton[iClose].hWndApp))
  143.         {
  144.         if((AppSound.EnableSound != 0) && (AppButton[iClose].NoSound == 0))
  145.             if(stricmp(AppSound.ProgramClose, "<none>") != 0)
  146.             sndPlaySound(AppSound.ProgramClose, SND_ASYNC | SND_NODEFAULT);
  147.         if(CloseApp(AppButton[iClose].hWndApp, hInst))
  148.             AppButton[iClose].ProgStatus = NOTALIVE;
  149.         InvalidateRect(hWndCurrentButton, (LPRECT) NULL, FALSE);
  150.         UpdateWindow(hWndCurrentButton);
  151.         }
  152.         else   // program doesn't exist anymore, start it again.
  153.         {
  154.         iActive = iClose+1;
  155.         if((AppSound.EnableSound != 0) && (AppButton[iClose].NoSound == 0))
  156.             if(stricmp(AppSound.ProgramStart, "<none>") != 0)
  157.             sndPlaySound(AppSound.ProgramStart, SND_ASYNC | SND_NODEFAULT);
  158.         ProgExec(hWndMain, (LPSTR)AppButton[iClose].ProgName, (LPSTR)AppButton[iClose].Params, (LPSTR)AppButton[iClose].StartDir, AppButton[iClose].ShowMode);
  159.         }
  160.         }
  161.     }
  162.     if((AppSystem.DoubleClick == 1) && (ClickMode == BN_CLICKED))
  163.     if(AppButton[iClose].ProgStatus == ALIVE)
  164.         BringWindowToTop(AppButton[iClose].hWndApp);
  165.     }
  166.  
  167. /*---------------------------------------------------------------------------/
  168. /                                         /
  169. /  Function : CheckProgStatus()                          /
  170. /                                         /
  171. /  Purpose  : Updates the status of a program to the current status.         /
  172. /                                         /
  173. /---------------------------------------------------------------------------*/
  174. VOID PASCAL CheckProgStatus(VOID)
  175.     {
  176.     int iCheck;
  177.  
  178.     for(iCheck=0;iCheck<AppWindow.nButtons;iCheck++)
  179.     {
  180.     if(AppButton[iCheck].ProgStatus == ALIVE)       // Appbar thinks app[i] exists
  181.         {
  182.         if(!IsWindow(AppButton[iCheck].hWndApp))       // app[i] doesn't exists anymore
  183.         {
  184.         AppButton[iCheck].ProgStatus = NOTALIVE;   // Appbar knows that now
  185.         InvalidateRect(hWndButton[iCheck+FirstAppButton], (LPRECT) NULL, FALSE);
  186.         }
  187.         }
  188.     }
  189.     }
  190.  
  191. /*--------------------------------------------------------------------------*/
  192. int AskForParameters(char *szParameters)
  193.     {
  194.     static DLGPROC lpfnAskDlgProc;
  195.     char szParams[256], szTemp[256], *szParam;
  196.  
  197.     strcpy(szParams, szParameters);
  198.  
  199.     szParam = strtok(szParams, "?");
  200.     strcpy(szTemp, szParam);
  201.     lpfnAskDlgProc = (DLGPROC) MakeProcInstance((FARPROC)AskDlgProc, hInst);
  202.     DialogBox(hInst, "AskDlg", hWndMain, lpfnAskDlgProc);
  203.     FreeProcInstance((FARPROC)lpfnAskDlgProc);
  204.     if(bExecuteProg)
  205.     {
  206.     strcat(szTemp, " ");
  207.     strcat(szTemp, szBuffer);
  208.     }
  209.     else
  210.     return FALSE;
  211.  
  212.     while((szParam = strtok(NULL, "?")) != NULL)
  213.     {
  214.     strcat(szTemp, szParam);
  215.     lpfnAskDlgProc = (DLGPROC) MakeProcInstance((FARPROC)AskDlgProc, hInst);
  216.     DialogBox(hInst, "AskDlg", hWndMain, lpfnAskDlgProc);
  217.     FreeProcInstance((FARPROC)lpfnAskDlgProc);
  218.     if(bExecuteProg)
  219.         {
  220.         strcat(szTemp, " ");
  221.         strcat(szTemp, szBuffer);
  222.         }
  223.     else
  224.         return FALSE;
  225.     }
  226.     strcpy(szParameters, szTemp);
  227.     }
  228.